const { DataTypes } = require("sequelize");

const requelize = require("../db/sequelize");

const Advertisement = requelize.define("db_advertisement", {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    unique: true,
    primaryKey: true,
    comment: "ID",
  },
  added_by: {
    type: DataTypes.STRING(64),
    allowNull: true,
    comment: "添加人ID",
  },
  title: {
    type: DataTypes.STRING(200),
    allowNull: true,
    comment: "广告标题",
  },
  url: {
    type: DataTypes.STRING,
    allowNull: true,
    comment: "广告URL地址",
  },

  type: {
    type: DataTypes.INTEGER(2),
    allowNull: true,
    comment: "广告类型(走字典)",
  },

  position: {
    type: DataTypes.INTEGER(2),
    allowNull: true,
    comment: "广告位置(走字典)",
  },
  status: {
    type: DataTypes.INTEGER(2),
    allowNull: true,
    comment: "广告状态(走字典)",
  },
  sort: {
    type: DataTypes.BIGINT,
    allowNull: true,
    comment: "排序",
  },
  link: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: "外链",
  },
  click: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: "点击量",
  },
  bg_color: {
    type: DataTypes.STRING(64),
    allowNull: true,
    comment: "背景颜色",
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: "描述",
  },
},
  {
    tableName: "db_advertisement",
    comment: "广告表",
  }
);

// 注释掉的代码块：这里原本是一个同步数据库表结构的调用，使用时需要解除注释并谨慎操作，因为它会强制同步表结构，可能导致数据丢失
// Advertisement.sync({ force: true });

// 导出用户模型，供其他模块使用
module.exports = Advertisement;
